using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    /// <summary> 
    ///Author: daiduong19051986@gmail.com 
    /// <summary>
    public class RuleSetHVJControl
    {
        #region Local Variable

        private string business;
        private RuleSetHVJDataAccess _objDAOHVJ;
        private RuleSetPRVDataAccess _objDAOPRV;
        #endregion Local Variable

        #region Method
        
        public RuleSetHVJControl(String bus)
        {
            business = bus;
            _objDAOHVJ = new RuleSetHVJDataAccess();
            _objDAOPRV = new RuleSetPRVDataAccess();
        }
        public RuleSetInfo Get(
        Int32 AUTO_ID,
        String RULESET_CODE,
        ref string sErr)
        {
            if (business == "HV")
            {
                return _objDAOHVJ.Get(
                AUTO_ID,
                RULESET_CODE,
                ref sErr);
            }
            else
            {
                return _objDAOPRV.Get(
                               AUTO_ID,
                               RULESET_CODE,
                               ref sErr);
            }
        }

        public DataTable GetAll(
        ref string sErr)
        {
            if (business == "HV")
            {
                return _objDAOHVJ.GetAll(
                ref sErr);
            }
            else
            {
                return _objDAOPRV.GetAll(
                  ref sErr);
            }
        }

        public Int32 Add(RuleSetInfo obj, ref string sErr)
        {
            if (business == "HV")
            {
                return _objDAOHVJ.Add(obj, ref sErr);
            }
            else
            {
                return _objDAOPRV.Add(obj, ref sErr);
            }
        }

        public string Update(RuleSetInfo obj)
        {
            if (business == "HV")
            {
                return _objDAOHVJ.Update(obj);
            }
            else
            { return _objDAOPRV.Update(obj); }
        }

        public string Delete(
        Int32 AUTO_ID,
        String RULESET_CODE
        )
        {
            if (business == "HV")
            {
                return _objDAOHVJ.Delete(
                AUTO_ID,
                RULESET_CODE
                );
            }
            else
            {
                return _objDAOPRV.Delete(
                   AUTO_ID,
                   RULESET_CODE
                   ); 
            }
        }
        public Boolean IsExist(
        Int32 AUTO_ID,
        String RULESET_CODE
        )
        {
            if (business == "HV")
            {
                return _objDAOHVJ.IsExist(
                AUTO_ID,
                RULESET_CODE
                );
            }
            else
            {
                return _objDAOPRV.IsExist(
                    AUTO_ID,
                    RULESET_CODE
                    );
            }
        }

       
        public string InsertUpdate(RuleSetInfo obj)
        {
            if (business == "HV")
            {
                string sErr = "";
                if (IsExist(
                obj.AUTO_ID,
                obj.RULESET_CODE
                ))
                {
                    sErr = _objDAOHVJ.Update(obj);
                }
                else
                    _objDAOHVJ.Add(obj, ref sErr);
                return sErr;
            }
            else
            {
                string sErr = "";
                if (IsExist(
                obj.AUTO_ID,
                obj.RULESET_CODE
                ))
                {
                    sErr = _objDAOPRV.Update(obj);
                }
                else
                    _objDAOPRV.Add(obj, ref sErr);
                return sErr;
            }

        }

        public DataTable GetTransferOut(string dtb, object from, object to, ref string sErr)
        {
            if (business == "HV")
            {
                return _objDAOHVJ.GetTransferOut(dtb, from, to, ref sErr);
            }
            else
            {
                return _objDAOPRV.GetTransferOut(dtb, from, to, ref sErr);
            }
        }

        public DataTable ToTransferInStruct()
        {
            RuleSetInfo inf = new RuleSetInfo();
            return inf.ToDataTable();
        }

        public string TransferIn(DataRow row)
        {
            RuleSetInfo inf = new RuleSetInfo(row);
            return InsertUpdate(inf);
        }
        #endregion Method


        public DataTable GetbyRuleSetCode(string RuleSetCode, ref string sErr)
        {
            if (business == "HV")
            {
                return _objDAOHVJ.GetbyRuleSetCode(RuleSetCode, ref sErr);
            }
            else
            {
                return _objDAOPRV.GetbyRuleSetCode(RuleSetCode, ref sErr);
            }
            
        }

        public DataTable GetbyRuleSetCode(string RuleSetCode, string strWhere, ref string sErr)
        {
            if (business == "HV")
            {
                return _objDAOHVJ.GetbyRuleSetCode(RuleSetCode,strWhere, ref sErr);
            }
            else
            {
                return _objDAOPRV.GetbyRuleSetCode(RuleSetCode, strWhere, ref sErr);
            }
        }
    }
}
